//
//  DYJQuestionHeaderTableViewCell.m
//  Piece
//
//  Created by dllo on 16/6/8.
//  Copyright © 2016年 Northeast Dianli University. All rights reserved.
//

#import "DYJQuestionHeaderTableViewCell.h"

@implementation DYJQuestionHeaderTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.titleLabel.font = [UIFont systemFontOfSize:17];
    self.titleLabel.numberOfLines = 0;
    
    self.questionLabel.font = [UIFont systemFontOfSize:15];
    self.questionLabel.numberOfLines = 0;
    
    self.userNameLabel.numberOfLines = 0;
    self.dateLabel.textAlignment = 2;
    self.dateLabel.textColor = [UIColor colorWithRed:0.80 green:0.83 blue:0.86 alpha:1.00];
    self.dateLabel.font = [UIFont systemFontOfSize:11];
}
- (void)setModel:(DYJQuestionContentModel *)model
{
    if (_model != model) {
        _model = model;
        self.titleLabel.text = model.question_title;
        self.questionLabel.text = model.question_content;
        self.userNameLabel.text = model.answer_title;
        
        NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init] ;
        [inputFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSDate *inputDate = [inputFormatter dateFromString:model.last_update_date];
        NSDateFormatter * outputFormatter = [[NSDateFormatter alloc]init];
        [outputFormatter setDateFormat:@"MMM dd,yyyy.EEE"];
        NSString *str = [outputFormatter stringFromDate:inputDate];
        self.dateLabel.text = str;
        
        CGRect titleRect = [self.titleLabel.text boundingRectWithSize:CGSizeMake(ScreenWidth - 20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17], NSFontAttributeName, nil] context:nil];
        self.titleLabel.frame = CGRectMake(10, 20, titleRect.size.width, titleRect.size.height);
        
        CGRect questionRect = [self.questionLabel.text boundingRectWithSize:CGSizeMake(ScreenWidth - 20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:15], NSFontAttributeName, nil] context:nil];
        self.questionLabel.frame = CGRectMake(10, self.titleLabel.frame.origin.y + self.titleLabel.frame.size.height + 10, questionRect.size.width, questionRect.size.height);

        
        CGRect userNameRect = [self.userNameLabel.text boundingRectWithSize:CGSizeMake(ScreenWidth - 20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:16], NSFontAttributeName, nil] context:nil];
        self.userNameLabel.frame = CGRectMake(10, self.lineView.frame.origin.y + 20, userNameRect.size.width, userNameRect.size.height);
        
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
